/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: HP
 * Date: 2023 -10 -09
 * Time: 20:57
 */
public class test1 {
    static class MyRunnable implements Runnable {
        @Override
        public void run() {
            while(!Thread.interrupted()){
                System.out.println("working---");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    //选择处理方式
                    break;
                }
            }
        }
    }
    public static void main(String[] args) {
        MyRunnable mr = new MyRunnable();
        Thread t = new Thread(mr);
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("thread interrupted");
        t.interrupt();
    }
}
